#include <plane.h>

#include <debug.h>
#include <unittest.h>

/**
 * DESC: Test plane operations
 * IMP: HIGH
 */

int main( int argc, char *argv[] )
{
  char *s;
  plane_t plane;
  vector3_t vector, point;

  debug_level = DEBUG_ERR;

  vector3_set( &plane.point, 10, 10, 10 );
  vector3_set( &plane.normal, 0, 10, 0 );

  vector3_set( &vector, 1, 1, 1 );
  vector3_set( &point,  20, 20, 30 );

  s = plane_str( plane );
  info( "plane  = %s\n", s );
  free( s );
  s = vector3_str( vector );
  info( "vector = %s\n", s );
  free( s );
  s = vector3_str( point );
  info( "point  = %s\n", s );
  free( s );


  vector3_t interception_point;

  int r = plane_intercept( plane, point, vector, &interception_point );

  assert_equal_int( r, 1 );
  assert_equal_double( interception_point.data[ 0 ], 10.0, DOUBLE_PRECISION );
  assert_equal_double( interception_point.data[ 1 ], 10.0, DOUBLE_PRECISION );
  assert_equal_double( interception_point.data[ 2 ], 20.0, DOUBLE_PRECISION );

  s = vector3_str( interception_point );
  info( "intercept at: %s\n", s );
  free( s );

  return 0;
}
